package com.gln.bloger.log;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * Project's Common Logging Class
 * Use Log4j and Apache common logging
 * 
 * @author LeoLeung
 * Date: 2008/01/02
 */
public final class Logging {
	/**
	 *  Static log object
	 */
	private static Log logger = null;
	
	static
	{
		try
		{
			/**
			 *  Get log object from log factory
			 */
			logger = LogFactory.getLog(Logging.class);
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
	}
	
	/**
	 * Output the debug level log
	 * 
	 * @param debug
	 */
	public static void debug(Object debug)
	{
		if ( null != logger && logger.isDebugEnabled() )
		{
			logger.debug(debug);
		}
	}
	
	/**
	 * Output the info level log
	 * 
	 * @param info
	 */
	public static void info(Object info)
	{
		if ( null != logger && logger.isInfoEnabled() )
		{
			logger.info(info);
		}
	}
	
	/**
	 * Output the warn level log
	 * 
	 * @param warn
	 */
	public static void warn(Object warn)
	{
		if ( null != logger && logger.isWarnEnabled() )
		{
			logger.warn(warn);
		}
	}
	
	/**
	 * Output the error level log
	 * 
	 * @param error
	 */
	public static void error(Object error)
	{
		if ( null != logger && logger.isErrorEnabled() )
		{
			logger.error(error);
		}
	}
	
	/**
	 * Output the trace level log
	 * 
	 * @param trace
	 */
	public static void trace(Object trace)
	{
		if ( null != logger && logger.isTraceEnabled() )
		{
			logger.trace(trace);
		}
	}
	
	/**
	 * Output the debug level log
	 * 
	 * @param debug
	 * @param debugE Throwable Object
	 */
	public static void debug(Object debug, Throwable debugE)
	{
		if ( null != logger && logger.isDebugEnabled() )
		{
			logger.debug(debug, debugE);
		}
	}
	
	/**
	 * Output the info level log
	 * 
	 * @param info
	 * @param infoE Throwable Object
	 */
	public static void info(Object info, Throwable infoE)
	{
		if ( null != logger && logger.isInfoEnabled() )
		{
			logger.info(info, infoE);
		}
	}
	
	/**
	 * Output the warn level log
	 * 
	 * @param warn
	 * @param warnE Throwable Object
	 */
	public static void warn(Object warn, Throwable warnE)
	{
		if ( null != logger && logger.isWarnEnabled() )
		{
			logger.warn(warn, warnE);
		}		
	}
	
	/**
	 * Output the error level log
	 * 
	 * @param error
	 * @param errorE Throwable Object
	 */
	public static void error(Object error, Throwable errorE)
	{
		if ( null != logger && logger.isErrorEnabled() )
		{
			logger.error(error, errorE);
		}
	}
	
	/**
	 * Output the trace level log
	 * 
	 * @param trace
	 * @param traceE Throwable Object
	 */
	public static void trace(Object trace, Throwable traceE)
	{
		if ( null != logger && logger.isTraceEnabled() )
		{
			logger.trace(trace, traceE);
		}
	}
}
